module MC {
		///let url = '/api/home/call?c=' + str;
	export function api(str: string, data: any={}, fun: Function = null, Err: Function = null) {
		let url = '/api/app/call/' + str;
		if (str[0] == '/') {
			url = str;
		}
		let head: any = {};
			  	if ($('#post_token').val()) {
						head['X-CSRF-TOKEN'] = $('#post_token').val();	
					}
		 
		var userInfo = JSON.parse(localStorage.getItem('userInfo'));
		if (userInfo) {
			var app_access = userInfo.app_access;
			var token = userInfo.token;
			if (!data.app_access) {
				data.app_access = app_access;
			}
			if (!data.token) {
				data.token = token;
			}
		}
		$.ajax({
			headers: head,
			url: url,
			type: "post",
			dataType: "json",
			data: data,
			success: function (json) {
				if (json.code == 0 || json.code == 200) {
					fun&&fun(json.data);
				} else {
					if (Err) {
						Err(json.data);
					} else {
						if (json.code == API.Login) {
							MC.login();
							return;
						}
						MC.msg.alert(json.msg);
					}
				}
				if (json.sql && json.sql.length > 0) {
					console.log(str, json.sql);
				}
			}
		});


	}



	export let HOST = 'http://www.fuzhuangchangongxiao.cn';
	export let $Pic = '/h5/images/logo-di.png';

	export function pImg($src: string) {
		if (!$src) {
			return HOST + $Pic;
		}
		if ($src[0] === '/') {
			$src = HOST + $src;
		}
		return $src;
	}

	let _isclick = false;
	/***  避免多次点击的 */
	export function click(Fun: Function) {
		if (_isclick) {
			return;
		}
		_isclick = true;
		Fun();
		setTimeout(() => {
			_isclick = false;
		}, 800);
	}
	/** 移除点击状态 */
	export function reclick() {
		_isclick = false;
	}








	/** 获取get参数 */
	export function get(n: string) {
		var m = window.location.search.match(new RegExp("(\\?|&)" + n + "=([^&]*)(&|$)"));
		return !m ? "" : decodeURIComponent(m[2]);
	}




	export function cookie(name: string, value: string, options: any = null) {
		if (typeof value != 'undefined') { // name and value given, set cookie
			options = options || {};
			if (value === null) {
				value = '';
				options.expires = -1;
			}
			var expires = '';
			if (!options.expires) {
				options.expires = 70;
			}
			if (!options.path) {
				options.path = '/';
			}
			if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
				var date;
				if (typeof options.expires == 'number') {
					date = new Date();
					date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
				} else {
					date = options.expires;
				}
				expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
			}
			var path = options.path ? '; path=' + options.path : '';
			var domain = options.domain ? '; domain=' + options.domain : '';
			var secure = options.secure ? '; secure' : '';
			document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
		} else { // only name given, get cookie
			var cookieValue = null;
			if (document.cookie && document.cookie != '') {
				var cookies = document.cookie.split(';');
				for (var i = 0; i < cookies.length; i++) {
					var cookie = jQuery.trim(cookies[i]);
					// Does this cookie string begin with the name we want?
					if (cookie.substring(0, name.length + 1) == (name + '=')) {
						cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
						break;
					}
				}
			}
			return cookieValue;
		}
	}


	export function back() {
		window.history.back(-1);
	}


	export enum API {
		/** 正常 */
		ok = 0,
		/** 权限错误 */
		Permission_error = -1,
		/** 参数错误 */
		Parameter_error = -2,
		/** 没有数据 */
		nullData = -3,
		/** 需要登录 */
		Login = -1001
	}



	export function login() {
		window.open('/h5/login/login.html', '_self');
	}

}



$(() => {

	$('body').on('click', '[call]', function () {
		let obj = $(this);
		let id = obj.attr('call');
		window.open('/h5/message/jobWin.html?uid=' + id, '_self');
		//console.log(id);
	});


}); 